#ifndef _CALENDAR_H
#define _CALENDAR_H

struct CalendarDate {
	long year;
	long month;
	long day;
};

class Calendar {
private:
	static const char monthLength[14];

	long year,month,day,hour,minute;
	double second;
	double julian;
	bool greg;

public:
	enum DAY_OF_WEEK {	
		SUNDAY			= 0,
		MONDAY			= 1,
		TUESDAY			= 2,
		WEDNESDAY		= 3,
		THURSDAY			= 4,
		FRIDAY			= 5,
		SATURDAY			= 6
	};

	Calendar();
	Calendar(long y,long m,double d,bool g=true);
	Calendar(long y,long m,double d,double h=0,double n=0,double s=0,bool g=true);
	Calendar(double jd,bool g=true);

	static double set(long y,long m,double d,bool g);
	static bool isLeap(long y,bool g);
	static void dayOfYearToDayAndMonth(long dy,bool l,long& dm,long& m);
	static CalendarDate julianToGregorian(long y,long m,long d);
	static CalendarDate gregorianToJulian(long y,long m,long d);
	static long INT(double value);

	void set(long y,long m,double d,double h=0,double n=0,double s=0,bool g=true);
	void set(double jd,bool g=true);
	void get(long& y,long& m,long& d,long& h,long& n,double& s) const;

	long getYear() const { return year; }
	long getMonth() const { return month; }
	long getDay() const { return day; }
	long getHour() const { return hour; }
	long getMinute() const { return minute; }
	double getSecond() const { return second; }
	bool isGregorian() const { return greg; }

	operator double() const { return julian; };

	DAY_OF_WEEK dayOfWeek() const;
	double dayOfYear() const;
	long daysInMonth() const;
	long daysInYear() const;
	bool isLeap() const { return isLeap(year,greg); }
	double fractionalYear() const;

};

#endif

